<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    
<%@page import="gruppe7.util.Html" %>
<%@page import="gruppe7.data.User" %>
<%@page import="gruppe7.data.UserException" %>
<%@page import="gruppe7.data.UserController" %>

<html>
<%
Html html = new Html(); 
UserController uc = UserController.getInstance();
%>

<% out.print(html.setHeader("Login")); %>

<body>
<jsp:include page="main_links.jsp" />

<div id ="content">
<div id="content-left-contact">

<%

out.println("<div id='content-left'>");
out.println("<h3><img src='images/login.png' /> Login</h3><br/>");

if(request.getAttribute("login") == null)
	request.setAttribute("login", "first");

if(!uc.isValidSession(request)) {
	if (request.getAttribute("login").equals("false")) {
		out.print("<p style='color: red;'>Wrong username or password!</p>");
		out.print(html.setFooter());
	}
	
	else out.println(html.LoginFormString(request));
}

else {
	
	if (request.getAttribute("login").equals("true")) {
		out.println("<p>Welcome old chap!</p><br/>");
		out.println("<p><a href='index.jsp'>Frontpage</a></p>");
	}
	
	else {
		out.println("<h3>You are already logged in!</h3><br/>");
    	out.println("<p><a href='Logout'>Logout?</a></p>");
	}
}
out.println("</div></div>");
out.println(html.setFooter());
%>
